home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / source / blt / bltdva.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-26  |  3.3 KB  |  119 lines

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include "blt.h"
  4. #include "dib.h"
  5. #include "dva.h"
  6.  
  7. /*----------------------------------------------------------------------------*\
  8. \*----------------------------------------------------------------------------*/
  9. void DrawDVA(HDC hdc, int x, int y, int dx, int dy);
  10. void DrawDVAX(HDC hdc, int x, int y, int dx, int dy);
  11.  
  12. /*----------------------------------------------------------------------------*\
  13. \*----------------------------------------------------------------------------*/
  14. extern "C" FAR PASCAL DVABlt(LPBITMAPINFOHEADER,LPVOID,LONG,LONG,LONG,LONG,
  15.     LPBITMAPINFOHEADER,LPVOID,LONG,LONG);
  16.  
  17. extern "C" FAR PASCAL StretchDIB(
  18.     LPBITMAPINFOHEADER,LPVOID,UINT,UINT,UINT,UINT,
  19.     LPBITMAPINFOHEADER,LPVOID,UINT,UINT,UINT,UINT);
  20.  
  21. typedef void (FAR PASCAL CONVERTPROC)(
  22.         LPVOID pd,              // --> dst.
  23.         LONG   dd,              // offset to start at
  24.         LONG   nd,              // dst_next_scan.
  25.         LPVOID ps,              // --> source.
  26.         LONG   ds,              // offset to start at
  27.         LONG   ns,              // src_next_scan.
  28.         LONG   dx,              // pixel count.
  29.         LONG   dy,              // scan count.
  30.         LPVOID pc);             // pixel convert table.
  31.  
  32. extern "C" CONVERTPROC copy_8_8, convert_8_8;
  33.  
  34. /*----------------------------------------------------------------------------*\
  35. \*----------------------------------------------------------------------------*/
  36.  
  37. HDVA hdva;
  38. BITMAPINFOHEADER biScreen;
  39. LPVOID lpScreen;
  40.  
  41. BOOL InitDVA(void)
  42. {
  43.     if (hdva != NULL)
  44.     {
  45.         if (lpbiApp)
  46.             return lpbiApp->biBitCount == biScreen.biBitCount;
  47.         else
  48.             return TRUE;
  49.     }
  50.  
  51.     HDC hdc = GetDC(NULL);
  52.     hdva = DVAOpenSurface(hdc, 0);
  53.     ReleaseDC(NULL,hdc);
  54.  
  55.     if (hdva)
  56.     {
  57.         lpScreen = DVAGetSurfacePtr(hdva);
  58.         biScreen = *DVAGetSurfaceFmt(hdva);
  59.     }
  60.  
  61.     return hdva != NULL;
  62. }
  63.  
  64. void DrawDVA(HDC hdc, int x, int y, int dx, int dy)
  65. {
  66.     DWORD dw;
  67.  
  68.     if (gfBackPal)
  69.     {
  70.         DrawDVAX(hdc, x, y, dx, dy);
  71.         return;
  72.     }
  73.  
  74.     dw = GetDCOrg(hdc);
  75.  
  76.     x = x + LOWORD(dw);
  77.     y = y + HIWORD(dw);
  78.  
  79.     if (DVABeginAccess(hdva, x, y, dx, dy))
  80.     {
  81.         y = y + dy-1;
  82.         y = abs((int)biScreen.biHeight)-1 - y;
  83.  
  84.         if (dx == bm.bmWidth && dy == bm.bmHeight)
  85.             DVABlt(&biScreen, lpScreen, x, y,
  86.                 bm.bmWidth * bm.bmBitsPixel/8,bm.bmHeight,
  87.                 lpbiApp, lpDibBits, 0, 0);
  88.         else
  89.             StretchDIB(&biScreen, lpScreen, x, y, dx, dy,
  90.                        lpbiApp, lpDibBits, 0, 0, bm.bmWidth, bm.bmHeight);
  91.  
  92.         DVAEndAccess(hdva);
  93.     }
  94. }
  95.  
  96. void DrawDVAX(HDC hdc, int x, int y, int dx, int dy)
  97. {
  98.     DWORD dw;
  99.  
  100.     dw = GetDCOrg(hdc);
  101.  
  102.     x = x + LOWORD(dw);
  103.     y = y + HIWORD(dw);
  104.  
  105.     if (DVABeginAccess(hdva, x, y, dx, dy))
  106.     {
  107.         y = y + bm.bmHeight-1;
  108.  
  109.         dw = (DWORD)(UINT)y * (DWORD)(UINT)DibWidthBytes(&biScreen) +
  110.              x * bm.bmBitsPixel/8;
  111.  
  112.         convert_8_8(lpScreen, dw, -(int)DibWidthBytes(&biScreen),
  113.                     lpBitmapBits, OffsetScan0, -(int)bm.bmWidthBytes,
  114.                     bm.bmWidth*bm.bmBitsPixel/8, bm.bmHeight, BitmapTranslate);
  115.  
  116.         DVAEndAccess(hdva);
  117.     }
  118. }
  119.